package TUILayer;
import ModelLayer.*;
import java.util.Scanner;
import java.util.ArrayList;


/**
 * Write a description of class LoanUI here.
 * 
 * @author (Allan Lie) 
 * @version (V1)
 */
public class LoanUI
{
    private Scanner keyboard;
    private Scanner keyboardString;
    
    public LoanUI()
    {
        this.keyboard = new Scanner(System.in);
        this.keyboardString = new Scanner(System.in);
    }
    
    public int readInt() {
        int i = 0;
        boolean ok = false;
        
        while(!ok) {
            try {
                i = this.keyboard.nextInt();
                ok = true;
            }catch(Exception e) {
                this.keyboard.nextLine();
            }
        }
        return i;
    }
    
    public String readLine() 
    {
        return this.keyboardString.nextLine();
    }
    
    public void writeLoanMenu()
    {
        System.out.println("\f *** Loan Menu ***");
        System.out.println(" (1) Show Loanouts");
        System.out.println(" (2) Add new Loan");
        System.out.println(" (3) Remove Loan");
        System.out.println("");
        System.out.println(" (9) Return");
        System.out.print("\n Make your choise: ");
    }
    
    public void writeSelectId() 
    {
        System.out.print("Enter a ID of a to continue: ");
    }   
        
    public void writeAddressbook()
    {
        System.out.println("\fAddressbook:");
    }
    public void writeOutPersons(ArrayList<Person> ppl) {
        
        if(ppl.size() > 0) {
            for(Person p : ppl)
            {
                System.out.println(p.getId() + ": " + p.getName());
                
            }
        } else {
            System.out.println("There is no Persons in the list!");

            
        }
    }
    
    public void writeOutDvds(ArrayList<Dvd> dvd)
    { 
        if(dvd.size() > 0)
        {
            for(Dvd d : dvd)
            {
                System.out.println(d.getId() + ": " + d.getTitle());
            }
        }
        else
        {
            System.out.println("There is no Dvds in the list!");
        }
    }
    public void writeOutLoans(ArrayList<Loan> loans)
    {
        if(loans.size() > 0)
        {
            for(Loan l : loans)
            {
                String title = l.getDvd().getTitle();
                String serial = l.getDvdCopy().getSerial();
                System.out.println(l.getId() + ": " + title + " (" + serial + ")");
            }
        }
        else 
        {
            System.out.println("There is no loans registred!");
        }
    }
        
    public void writeDvdList() 
    {
        System.out.println("\fDVD List:");
    }
    
    public void writeLoanList()
    {
        System.out.println("\fLoan List:");
    }
    
    public void writeBlankLine() 
    {
        System.out.println("");
    }
     
    public void writeEnterToContinue()
    {
        System.out.println("> Press enter to continue");
    }
    
    public void writeLoanId()
    {
        System.out.println("\fType your Loan ID");
    }
    
    public void writeEnterPeriod() {
        System.out.print("Enter a period (days): ");
    }
    
    public void writeSureYouWantToLDelete() {
        System.out.print("Are you sure you want to remove the loan? (y/N): ");
    }
    
    public void writeLoanRemoved() {
        System.out.println("The loan was removed!");
    }
    
    public void writeReturnedToLate() {
        System.out.println("The DVD is returned too late!");
    }
    
    public void writeLoanDetails(Loan loan)
    {
        System.out.println("\f=== Loan Details ===");
        System.out.println("Id: " + loan.getId());
        System.out.println("Rental date: " + loan.getDate());
        System.out.println("Period: " + loan.getPeriod() + " day(s)");
    }
}